const express = require("express");
const cors = require("cors");

const app = express();

var corsOptions = {
  origin: "http://localhost:8081"
};

app.use(cors(corsOptions));

// parse requests of content-type - application/json
app.use(express.json());

// parse requests of content-type - application/x-www-form-urlencoded
app.use(express.urlencoded({ extended: true }));

// simple route
app.get("/", (req, res) => {
  // res.json({ message: "Welcome to bezkoder application." });
  res.send('123');
});


const db = require("./models/index.js");
db.sequelize.sync({ force: true }).then(res => {
  console.log(res);
  console.log('database connection success');
}).catch(err => {
  console.log(err);
  console.log('database fail')
})

require('./router/user.js')(app)

// set port, listen for requests
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
  console.log(`Server is running on port ${PORT}.`);
});